package com.novabluetooth.views.twj;

import android.annotation.SuppressLint;
import android.text.TextUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

/**
 * author : xiaoxin
 * date   : 2020/10/28 21:19
 * desc   :
 * update :
 */
public class TwjConstans {

    //爱奥乐红外体温计  型号 e127
    public final static String DEVICE_NAME = "Bioland-IT";
    public static String DEVICE_NAME_TYPENAME = "爱奥乐体温计";

    public static String Bioland_BP = "Bioland-BPM";
    public static String Bioland_BP_NAME = "爱奥乐血压计";

    public static String Bioland_BG = "Bioland-BGM";
    public static String Bioland_BG_NAME = "爱奥乐血糖";

    public static String GATT_SERVICE_PRIMARY = "00001000-0000-1000-8000-00805f9b34fb";
    public static String CHARACTERISTIC_WRITEABLE = "00001001-0000-1000-8000-00805f9b34fb";
    public static String CHARACTERISTIC_READABLE = "00001002-0000-1000-8000-00805f9b34fb";

    public static String GATT_SERVICE_PRIMARYNEW1 = "0000ffb0-0000-1000-8000-00805f9b34fb";
    public static String CHARACTERISTIC_WRITEABLENEW1 = "0000ffb1-0000-1000-8000-00805f9b34fb";
    public static String CHARACTERISTIC_READABLENEW1 = "0000ffb2-0000-1000-8000-00805f9b34fb";

    // 血压计 启动测量
    public static final String start_01 = "5A0A00100502OF213BE9";
    public static final String start_02 = "5A0A01100502OF213BE9";
    // 血压计 停止测量
    public static final String stop = "5A0A02100502OF213BEA";
    // 血压计 数据确认包05H
    public static final String sure_data = "5AOA05100502OF213BED";


    public static String getSendHex(int sendPack) {
        String time = getCurrentDateTime("yy-MM-dd-HH-mm-ss");
        String[] arrTime = time.split("-");
        if (arrTime.length == 6) {
            int index0 = 90;
            int index1 = 10;
            int index2 = sendPack;//00 包 03包
            int index3 = Integer.parseInt(arrTime[0]);//年
            int index4 = Integer.parseInt(arrTime[1]);//月
            int index5 = Integer.parseInt(arrTime[2]);//日
            int index6 = Integer.parseInt(arrTime[3]);//时
            int index7 = Integer.parseInt(arrTime[4]);//分
            int index8 = Integer.parseInt(arrTime[5]);//秒
            int index9 = index0 + index1 + index2 + index3 + index4 + index5 + index6 + index7 + index8 + 2;
            if (index9 > 255) {
                index9 = index9 % 255;
            }

            byte[] data2 = new byte[]{(byte) index0, (byte) index1, (byte) index2, (byte) index3,
                    (byte) index4, (byte) index5, (byte) index6, (byte) index7, (byte) index8, (byte) index9};
            return ZHexUtil.encodeHexStr(data2).toUpperCase();
        }
        return "";
    }

    @SuppressLint("SimpleDateFormat")
    public static String getCurrentDateTime(String format) {
        return simpleDateFormat(format, new Date());
    }

    public static String simpleDateFormat(String format, Date date) {
        if (TextUtils.isEmpty(format)) {
            format = "yyyy-MM-dd HH:mm:ss";
        }
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        sdf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        String content = sdf.format(date);
        return content;
    }

}
